package BehavioralPattern.Iterator;

import java.util.ArrayList;
import java.util.List;

public class Client {
    public static void main(String[] args) {
        List<Object> products = new ArrayList<Object>();
        products.add("A");
        products.add("B");
        products.add("C");
        products.add("D");
        products.add("E");

        AbstractObjectList list;
        AbstractIterator abstractIterator;

        list = new ProductList(products);   // 创建聚合对象
        abstractIterator = list.createIterator();   // 创建迭代器对象

        System.out.println("正向遍历：");
        while (!abstractIterator.isLast()) {
            System.out.print(abstractIterator.getNextItem() + ",");
            abstractIterator.next();
        }

        System.out.println();
        System.out.println("------------------------------------------");

        System.out.println("反向遍历：");
        while (!abstractIterator.isFirst()) {
            System.out.print(abstractIterator.getPreviousItem() + ",");
            abstractIterator.previous();
        }
    }


}
